package com.flute.icrawler.framework.processor;

import com.flute.icrawler.app.processor.AbstractProcessor;
import com.flute.icrawler.framework.framework.CrawlUrl;
import com.flute.icrawler.framework.framework.IProcessor;
import com.flute.icrawler.framework.framework.container.AdditionalUrlInformation;
import com.flute.icrawler.framework.framework.container.NumberStringValue;
import com.flute.icrawler.framework.framework.container.AdditionalUrlInformation.Additionals;
import com.flute.icrawler.framework.processor.result.AddUrlProcessorResult;

public class Print4Processor extends AbstractProcessor {

	@Override
	public void process(CrawlUrl url) {

		if (url.getUrl().contains("163")) {
			AddUrlProcessorResult apr = new AddUrlProcessorResult();
			for (int i = 0; i < 10; i++) {
				CrawlUrl newUrl = new CrawlUrl(url.getJob(), url.getUrl() + i);

				AdditionalUrlInformation info = url
						.getAdditionalUrlInformation().newInstance();

				info.updateValue(Additionals.UpdateCount,
						new NumberStringValue(0));

				newUrl.setAdditionalUrlInformation(info);

				apr.addUrl(newUrl);
			}
			url.registerProcessorResult(apr);
		}

		// 增加带排序因子的链接
		AddUrlProcessorResult apr = new AddUrlProcessorResult();
		CrawlUrl newUrl = new CrawlUrl(url.getJob(), url.getUrl() + "update");
		AdditionalUrlInformation info = url.getAdditionalUrlInformation()
				.newInstance();
		info.updateValue(Additionals.UpdateCount, new NumberStringValue(0));
		newUrl.setAdditionalUrlInformation(info);
		apr.addUrl(newUrl);
		url.registerProcessorResult(apr);
		// 增加带排序因子的链接

		// System.out.println("4 print:" + url.getUrl());
	}
}
